import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ViewController} from 'ionic-angular';
import {CalendarComponentOptions} from "ion2-calendar";
import {DialogProvider} from "@providers/dialog";

/**
 * 日期范围选择控件
 */

@IonicPage()
@Component({
  selector: 'page-datepicker',
  templateUrl: 'datepicker.html',
})
export class DatePickerPage {
  dateRange: { from: string; to: string; };
  // startDate: string;
  // endDate: string;
  optionsRange: CalendarComponentOptions = {
    pickMode: 'range',
    monthFormat: 'YYYY-MM',
    from: new Date(2000, 0, 1),
    weekdays: ['日', '一', '二', '三', '四', '五', '六'],
    monthPickerFormat: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
  };

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private viewCtrl: ViewController,
              private dialog: DialogProvider) {
  }

  dismiss(data?: any) {
    this.viewCtrl.dismiss(data);
  }

  ionViewDidLoad() {

  }

  submit() {
    if (this.dateRange) {
      this.dismiss(this.dateRange);
    } else {
      this.dialog.showAlert('请选择日期！');
    }
  }
}
